package com.spring.boot.controller;

import com.alibaba.fastjson.JSONObject;
import com.spring.boot.bean.Users;
import com.spring.boot.service.UserService;
import com.spring.boot.utils.Helper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: springboot_vue
 * @description: 用户管理控制器
 * @author: ry
 * @create: 2018-08-15 16:33
 **/
@RestController
@RequestMapping("api")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/create",method = RequestMethod.POST)
    public String newUser(HttpServletRequest request) throws Exception{
        JSONObject json= Helper.getjson(request);
        System.out.println("请求得到的数据---" + json.getString("username"));
        Users users = new Users();
        String jsons = json.toJSONString();
        users = JSONObject.parseObject(jsons, Users.class);
        userService.insertUser("datasources", users);
        System.out.println(users.getUsername());
        return "2321324";
    }
}
